<template>
  <div style="height: 100%; width: 100%; position: absolute; top: 5px">
    <div class="volumeIncomBar" style="height: 100%; width: 100%"></div>
  </div>
</template>
 <script>
export default {
  name: "volumeIncomBar",
  data() {
    return {
      show: true,
      myChart: null,
    };
  },
  props: {
    volumeIncomeData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  watch: {
    volumeIncomeData(val) {
      // var min = Math.min.apply(null, val.yAxis);
      var maxData = Math.max.apply(null, val.yAxis);
      var minData = Math.min.apply(null, val.yAxis);
      this.genData1(val);
      this.getPie1(val, maxData, minData);
    },
  },
  mounted() {
    var maxData = Math.max.apply(null, this.volumeIncomeData.yAxis);
    var minData = Math.min.apply(null, this.volumeIncomeData.yAxis);
    this.genData1(this.volumeIncomeData);
    this.getPie1(this.volumeIncomeData, maxData, minData);
  },
  methods: {
    genData1(val) {
      var datalsit = [];
      val.yAxis &&
        val.yAxis.map((item, index) => {
          let obj = {};
          var label = { color: "" };
          obj["value"] = item;
          if (item < 0) {
            if (item != Math.max.apply(null, val.yAxis)) {
              label = {
                show: true,
                position: "bottom",
                color: "#9399b6",
              };
            } else {
              label = {
                show: true,
                position: "bottom",
                color: "#9399b6",
              };
            }
            var itemStyle = {
              barBorderRadius: [0, 0, 10, 10],
            };
            obj["label"] = label;
            obj["itemStyle"] = itemStyle;
          } else {
            if (item != Math.max.apply(null, val.yAxis)) {
              label = {
                show: true,
                position: "top",
                color: "#9399b6",
              };
            } else {
              label = {
                show: true,
                position: "top",
                color: "#9399b6",
              };
            }
            var itemStyle = {
              barBorderRadius: [10, 10, 0, 0],
            };
            obj["label"] = label;
            obj["itemStyle"] = itemStyle;
          }
          datalsit.push(obj);
        });
      return datalsit;
    },
    getPie1(val, maxData, minData) {
      var datalsit = this.genData1(val);
      const that = this;
      this.myChart = this.$echarts.init(
        document.querySelector(".volumeIncomBar")
      );
      let option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          formatter: "{c0}万户",
        },
        grid: {
          top: "50px",
          left: "50px",
          right: "30px",
          bottom: "80px",
        },
        legend: {
          data: [val.titleIncreaseName],
          right: "80",
          top: "15",
          textStyle: { color: "#000" },
        },
        xAxis: {
          type: "category",
          // boundaryGap: false,
          axisLabel: {
            interval: 0,
            rotate: 40,
          },
          axisTick: {
            show: false,
          },
          data: val.xAxis,
          axisLine: {
            show: true,
            lineStyle: {
              color: "#9399b6",
            },
          },
        },
        yAxis: [
          {
            type: "value",
            // min: (minData-(minData+maxData1)%2)*2.2,
            splitLine: {
              show: false,
              lineStyle: {
                type: "dashed",
              },
            }, //去除网格线
            axisLabel: {
              show: true,
            },
            splitArea: {
              show: true,
              areaStyle: {
                color: "#fff",
              },
            },
            axisTick: {
              //y轴刻度线
              show: false,
            },
            axisLine: {
              //y轴
              show: true,
              lineStyle: {
                color: "#9399b6",
              },
            },
          },
        ],
        dataZoom: [
          {
            show: true,
            // start:0,
            // end: 20,
            startValue: val.xAxis.length - 12,
            endValue: val.xAxis.length - 1,
            backgroundColor: "#EBEDF3",
            showDataShadow: false,
            borderRadius: [20, 20],
            fillerColor: "#BEC5D8",
            height: 13,
            width: 300,
            left: "30%",
            bottom: 10,
          },
        ],
        series: [
          {
            type: "bar",
            name: val.titleIncreaseName,
            data: datalsit,
            barWidth: 10,
            itemStyle: {
              //  color: '#7f92f7',
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#49d6fe" }, //柱图渐变色
                { offset: 0.5, color: "#47c9fe" },
                { offset: 0.75, color: "#44b3fd" }, //柱图渐变色
                { offset: 1, color: "#41a1fd" }, //柱图渐变色
              ]),
              //    normal:{
              //      color: function(params) {
              //
              //         var c="";
              //         if(params.data.value == maxData){
              //           c='#7ed093'
              //         }else{
              //           c='#7f92f7'
              //         }
              //          return c;
              //          },
              // }
            },
          },
        ],
      };
      this.myChart.setOption(option);
    },
  },
};
</script>

 <style scoped lang="scss">
// .volumeIncomBar{
//  /deep/ div{
//    width: 100% !important;
//  }
// }
</style>
